package com.haredot.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.haredot.desensitize.JsonDesensitize;
import com.haredot.desensitize.enums.DesensitizeType;
import com.haredot.validation.Insert;
import com.haredot.validation.Update;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;

import java.time.LocalDateTime;

@TableName("tb_user")
public class User {

    @TableId(type = IdType.AUTO)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id ;

    @TableField("tel")
    @JsonDesensitize(type = DesensitizeType.TEL)
    @NotEmpty(groups = {Insert.class, Update.class}, message = "手机号不允许为空")
    @Pattern(groups = {Insert.class, Update.class}, regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
    private String tel ;

    @TableField("name")
    @NotEmpty(groups = Insert.class, message = "姓名不允许为空")
    @Pattern(groups = Insert.class, regexp = "^[\\u4e00-\\u9fa5]{2,4}$", message = "姓名必须是汉字、且字符数为 2 ~ 4")
    private String name ;

    @TableField("password")
    @JsonDesensitize(type = DesensitizeType.PASSWORD)
    @NotEmpty(groups = {Insert.class, Update.class}, message = "密码不允许为空")
    private String password ;

    @TableField("class_name")
    @NotEmpty(groups = {Insert.class}, message = "班级不允许为空")
    @Pattern(groups = Insert.class, regexp = "^[a-zA-Z]+\\d{4}$", message = "班级格式必须是字母+四位数字")
    private String className ;

    @TableField("role")
    @NotNull(groups = {Insert.class, Update.class}, message = "角色不允许为空")
    private Integer role ;

    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime ;

    @TableField(value = "update_time", fill = FieldFill.UPDATE)
    private LocalDateTime updateTime ;

    private boolean expire ;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public Integer getRole() {
        return role;
    }

    public void setRole(Integer role) {
        this.role = role;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public boolean isExpire() {
        return expire;
    }

    public void setExpire(boolean expire) {
        this.expire = expire;
    }
}
